import api from '@/services/organization/menu-management';

export type Menu = MenuManagementApi.InfoResponse;
export const getList = async (params: Requestor.ListRequestParams) => {
  const res = await api.getList<Menu>(params);
  const tableData: Requestor.TableFormatedData<Menu> = {
    data: res.listData,
    current: res.page + 1,
    pageSize: res.limit,
    total: res.count,
    success: res.success,
  };

  return tableData;
};
export const getAllList = async () => {
  const res = await api.getAllList<Menu[]>();
  return res.data;
};
export const getOneList = async () => {
  const res = await api.getOneList<Menu[]>();
  return res.data;
};
export const getInfo = async (params: MenuManagementApi.InfoParams) => {
  const res = await api.getInfo<Menu>(params);
  return res.data;
};
export const create = async (params: MenuManagementApi.CreateParams) => {
  const data = await api.create(params);
  return data;
};
export const update = async (params: MenuManagementApi.UpdateParams) => {
  const data = await api.update(params);
  return data;
};
export const remove = async (params: MenuManagementApi.DeleteParams) => {
  const data = await api.remove(params);
  return data;
};
export const getRelation = async (params: MenuManagementApi.GetRelationParams) => {
  const res = await api.getRelation(params);
  return res.data;
};
export const postRelation = async (params: MenuManagementApi.PostRelationParams) => {
  const data = await api.postRelation(params);
  return data;
};
export default {
  getList,
  getAllList,
  getOneList,
  getInfo,
  create,
  update,
  remove,
  getRelation,
  postRelation,
};
